<template>
	<view>
		<view class="member-top">
			<template v-if="!member.image">
				<!-- 没有登录时 空白图-->
				<image src="../../static/image/empty-tx.png" class="member-tx"></image>
			</template>
			<template v-else>
				<!-- 登录成功的图片由后端提供 -->
				<image :src="member.image" class="member-tx"></image>
			</template>
			
			<view class="userInfo">
				<view class="loginReg" v-if="this.$store.state.isLogin == 0">
					<navigator url="../login/login" hover-class="none">登录/注册</navigator>
				</view>
				<view class="loginInfo" v-else>
					<template v-if="!member.nickname">
						<!-- 么有昵称时 -->
						<view class="username">小鸡吃米</view>
					</template>
					<template v-else>
						<text class="username">{{member.nickname}}</text>
					</template>
					
					<text class="nickname">{{member.telphone}}</text>
				</view>
			</view>
			
			<view class="ewm">
				<image src="../../static/image/ewm.png" mode=""></image>
			</view>
			<view class="memberIcon">
				<i class="iconfont">&#xe612;</i>
				<i class="iconfont">&#xe614;</i>
			</view>
			
		</view>
		
<!-- 		//订单信息 -->
		<view class="orderStatus">
			<view class="orderItem">
				<image src="../../static/image/member-icon1.png" mode=""></image>
				<text>代付款</text>
			</view>
			<view class="orderItem">
				<image src="../../static/image/member-icon2.png" mode=""></image>
				<text>待收获</text>
			</view>
			<view class="orderItem">
				<image src="../../static/image/member-icon3.png" mode=""></image>
				<text>代评价</text>
			</view>
			<view class="orderItem">
				<image src="../../static/image/member-icon4.png" mode=""></image>
				<text>全部订单</text>
			</view>
		</view>
		
	<!-- 	分割线 -->
	<view class="splitLine"></view>
	
<!-- 	菜单信息 -->
		<view class="menuList">
			<view class="menuItem" @click="hrefList('../address/list')">
				<image src="../../static/image/member-menu1.png" mode=""></image>
				<text>收货地址</text>
				<i class="iconfont">&#xe60b;</i>
			</view>
			<view class="menuItem">
				<image src="../../static/image/member-menu2.png" mode=""></image>
				<text>在线客服</text>
				<i class="iconfont">&#xe60b;</i>
			</view>
			<view class="menuItem">
				<image src="../../static/image/member-menu3.png" mode=""></image>
				<text>邀请有礼</text>
				<i class="iconfont">&#xe60b;</i>
			</view>
			<view class="menuItem">
				<image src="../../static/image/member-menu4.png" mode=""></image>
				<text>关于我们</text>
				<i class="iconfont">&#xe60b;</i>
			</view>
		</view>
		
	<!-- 	退出登录 -->
	<view class="loginout" @click="loginOut" v-if="this.$store.state.isLogin">
		退出登录
	</view>
	</view>
</template>

<script>
	import {request} from '../../utils/require.js'
	import href from '../../utils/href.js'
	export default {
		data() {
			return {
				
				code:'',
				member:[]
			}
		},
		
		onLoad() {
			// this.getData()
		},
		onShow(){
			// 生命周期 每次进来都会刷新页面
			this.getData()
		},
		methods: {
			// 收货地址的跳转要经过拦截
			hrefList(url){
				href(url)
			},
			//退出登录
			loginOut(){
				this.$store.commit('loginOut')
			},
			//请求数据
			getData(){
				request('/member/index').then(res=>{
					console.log(res)
						// this.code = res.code
					if(res.code == 1){
						// 登录成功执行方法改变状态机isLogin值
						this.$store.commit('login')
						this.code = 1
						this.member = res.data
					}
				})
				// uni.request({
				// 	url:this.apiUrl + '/member/index',
				// 	method:'POST',
				// 	header:{
				// 		'token':uni.getStorageSync('token')
				// 	},
				// 	success:(res)=>{
				// 		// 根据请求得到的数据里面的tcode来判断登录
				// 		console.log(res.data)
				// 		if(res.data.tcode == 0){
				// 			this.tcode = 0
				// 		}
				// 		//登录成功时
				// 		if(res.data.code == 1){
				// 			this.code = 1
				// 			this.member = res.data.data
				// 		}
				// 		// token失效时 会返回一个新的token 用这个token重新请求数据 此时code为2
				// 		if( res.data.code == 2){
				// 			uni.setStorageSync('token', res.data.token)
				// 			uni.request({
				// 				url:this.apiUrl + '/member/index',
				// 				method:'POST',
				// 				header:{
				// 					'token':uni.getStorageSync('token')
				// 				},
				// 				success:(res)=>{
				// 					if(res.data.code == 1){
				// 						this.code = 1
				// 						this.member = res.data.data
				// 					}
				// 				}
				// 			})
				// 		}
				// 		// 伪造的token登录时 清空token 赋值tcode为0
				// 		if( res.data.code == 3){
				// 			this.tcode = 0
				// 			uni.setStorageSync('token', '')
				// 		}
				// 		// 防止有token 没有用户数据的访问 提高性能
				// 		if( res.data.code == 4){
				// 			this.tcode = 0
				// 			uni.setStorageSync('token', '')
				// 		}
				// 	}
					
				// })
			}
		}
	}
</script>

<style>
.member-top{
	height: 336rpx;
	width: 100%;
	background: #0086B3;
	position: relative;
}
.member-top:after{
	content: ''; /* // 主要为了撑开div */
	display: block;
	width: 100%;
	height: 50rpx;
	background: #fff;
	top: 290rpx;
	position: absolute;
	border-radius: 50% 50% 0 0;
}
.member-tx{
	width: 110rpx;
	height: 110rpx;
	border-radius: 50%;
	top: 110rpx;
	left: 30rpx;
	position: absolute;
}
.loginReg{
	width: 160rpx;
	height: 45rpx;
	line-height: 45rpx;
	text-align: center;
	font-size: 28rpx;
	color: #fff;
	border: 1rpx solid #fff;
	border-radius: 10rpx;
	left: 150rpx;
	top: 80rpx;
	position: absolute;
}
.loginInfo{
	left: 160rpx;
	top: 130rpx;
	position: absolute;
}
.loginInfo text.username{
	height: 42rpx;
	line-height: 42rpx;
	font-size: 28rpx;
	color: #fff;
	display: block;
}
.loginInfo text.nickname{
	height: 42rpx;
	line-height: 42rpx;
	font-size: 28rpx;
	color: #fff;
	display: block;
}
.ewm{
	height: 35rpx;
	width: 35rpx;
	position: absolute;
	right: 30rpx;
	top: 180rpx;
}
.ewm image{
	width: 35rpx;
	height: 35rpx;
}
.memberIcon{
	position: absolute;
	top: 50rpx;
	right: 30rpx;
	color: #fff;
}
.memberIcon i{
	margin-left: 35rpx;
}

.orderStatus{
	display: flex;
	justify-content: space-around;
}
.orderItem image{
	width: 70rpx;
	height: 56rpx;
	display: block;
	margin: 0 auto;
}
.orderItem text{
	font-size: 28rpx;
	line-height: 80rpx;
	display: block;
	text-align: center;
	padding-bottom: 10rpx;
}

.splitLine{
	height: 20rpx;
	width: 100%;
	background: #f5f5f5;
}


.menuItem{
	margin: 0 30rpx;
	height: 90rpx;
	font-size: 28rpx;
	border-bottom: 1rpx solid #e5e5e5;
	display: flex;
	align-items: center;
	position: relative;
}
/* .menuItem:nth-last-child(1){border-bottom: none;} */
.menuItem:nth-of-type(4){border-bottom: none;} /* 和上面的一样道理 */
.menuItem image{
	width: 30rpx;
	height: 30rpx;
	margin-right: 25rpx;
	
}
.menuItem i{
	/* width: 26rpx;
		height: 26rpx;  */
	position: absolute;
	right: 0;
	font-size: 30rpx;
}
.loginout{
	height: 85rpx;
	line-height: 85rpx;
	margin: 30rpx;
	background-color: pink;
	font-size: 28rpx;
	color: #000;
	border-color: 1rpx solid #e5e5e5;
	text-align: center;
}

</style>
